package com.atguigu.tingshu.live.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.live.service.LiveRoomService;
import com.atguigu.tingshu.model.live.LiveRoom;
import com.atguigu.tingshu.vo.live.LiveRoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/live/liveRoom")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LiveRoomApiController {

	@Autowired
	private LiveRoomService liveRoomService;
	@GuiGuLogin
	@GetMapping("getCurrentLive")
	public Result<LiveRoom> getCurrentLive(){
		LiveRoom liveRoom =liveRoomService.getCurrentLive();
		return Result.ok(liveRoom);
	}

	@GuiGuLogin
	@PostMapping("saveLiveRoom")
	public Result<LiveRoom> saveLiveRoom(@RequestBody LiveRoomVo liveRoomVo){
		LiveRoom liveRoom =liveRoomService.saveLiveRoom(liveRoomVo);
		return Result.ok(liveRoom);
	}

	@GetMapping("getById/{id}")
	public Result<LiveRoom> getById(@PathVariable Long id){
		LiveRoom liveRoom =liveRoomService.getById(id);
		return Result.ok(liveRoom);
	}

	@GetMapping("findLiveList")
	public Result<List<LiveRoom>> findLiveList(){
		List<LiveRoom> liveRoomList =liveRoomService.findLiveList();
		return Result.ok(liveRoomList);
	}
}

